package com.zdj.presentation.modules.user.vms;

import android.databinding.BindingAdapter;
import android.databinding.ObservableField;
import android.widget.ImageView;

import com.zdj.aoplibrary.annotations.DebugTrace;
import com.zdj.presentation.base.BaseActivity;
import com.zdj.presentation.base.BaseApplication;
import com.zdj.presentation.base.BaseViewModel;
import com.zdj.presentation.helpers.ImageLoadHelper;
import com.zdj.presentation.mappers.LoginInfoMapperUserModel;
import com.zdj.presentation.modules.user.models.UserModel;
import com.zdj.utils.LogLevel;
import com.zdj.utils.MyLogUtil;

/**
 * Created by zdj on 16-6-6.
 */

public class UserDetailVm extends BaseViewModel {

    public final ObservableField<UserModel> userObs = new ObservableField<>();

    @DebugTrace(lever = LogLevel.ERROR)
    public UserDetailVm(BaseActivity baseActivity) {
        super(baseActivity);
        mapper = new LoginInfoMapperUserModel();
    }

    @BaseViewModel.Command
    public void loadUserDetail(){
        userObs.set((UserModel)mapper.one2one(BaseApplication.sLoginInfo));
    }


    @BindingAdapter("imageUrl")
    public static void loadImage(ImageView imageView, String imageUrl) {
        MyLogUtil.d("UserDetailVm", "loadImage: 设置imageview图片");
        ImageLoadHelper.loadImageByGlide(imageView.getContext(),imageUrl,imageView);
    }

}
